<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!--引入校验手机号js代码-->
    <script src="../plugins/healthmobile.js"></script>
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约列表管理
            <small>列表管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表管理</el-breadcrumb-item>
            <el-breadcrumb-item>列表管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                <el-button type="primary" class="butT" @click="back2Page1()">返回第一页</el-button>
                <div style="margin-top: 8px"></div>
                <el-button type="danger" @click="deList">批量删除</el-button>
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row
                      ref="multipleTable" tooltip-effect="dark"
                      style="width: 100%"
                      @selection-change="handleSelectionChange">
                <el-table-column type="selection"></el-table-column>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <!--隐藏ID属性-->
                <el-table-column prop="id" align="center" label="预约编号" v-if="show"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="姓名" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确定预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="9">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name" placeholder="请输入姓名"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="10">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard" placeholder="请输入身份证号"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>

                                        <el-col :span="9">
                                            <el-form-item label="年龄" prop="age">
                                                <el-input v-model="formData.age" placeholder="请输入年龄"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="10">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber" placeholder="请输入手机号"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="9">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="9">
                                            <el-form-item label="出生日期" prop="birthday">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="9">
                                            <el-form-item label="婚姻状态">
                                                <el-select v-model="formData.remark" placeholder="请输入您的婚姻状况">
                                                    <el-option label="已婚" value="0"></el-option>
                                                    <el-option label="未婚" value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="9">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th width="30px">选择</th>
                                            <th>套餐名称</th>
                                            <th>适用性别</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox"
                                                       :value="c.id">
                                            </td>
                                            <td width="200px">
                                                <label :for="c.id">{{c.name}}</label>
                                            </td>
                                            <td width="80px">
                                                <label :for="c.id">{{c.sex=='0'?'不限':c.sex=='1'?'男':'女'}}&nbsp;</label>
                                            </td>
                                            <td>
                                                <label :for="c.id">{{c.remark}}</label>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑标签弹层 (没做)-->
            <div class="add-form">
                <el-dialog title="编辑预约信息" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="9">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name" placeholder="请输入姓名"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="10">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard" placeholder="请输入身份证号"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>

                                        <el-col :span="9">
                                            <el-form-item label="年龄" prop="age">
                                                <el-input v-model="formData.age" placeholder="请输入年龄"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="10">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber" placeholder="请输入手机号"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="9">
                                            <el-form-item label="性别" prop="sex">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="9">
                                            <el-form-item label="出生日期" prop="birthday">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="9">
                                            <el-form-item label="婚姻状态">
                                                <el-select v-model="formData.remark" placeholder="请输入您的婚姻状况">
                                                    <el-option label="已婚" value="0"></el-option>
                                                    <el-option label="未婚" value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="9">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th width="30px">选择</th>
                                            <th>套餐名称</th>
                                            <th>适用性别</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox"
                                                       :value="c.id">
                                            </td>
                                            <td width="200px">
                                                <label :for="c.id">{{c.name}}</label>
                                            </td>
                                            <td width="80px">
                                                <label :for="c.id">{{c.sex=='0'?'不限':c.sex=='1'?'男':'女'}}&nbsp;</label>
                                            </td>
                                            <td>
                                                <label :for="c.id">{{c.remark}}</label>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit(scope.row)">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            show:false,//隐藏列表中的ID属性值
            checkIds: [],//复选框中的多条ID值
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            setmealIds: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                idCard: [{required: true, message: '身份证为必填项', trigger: 'blur'}],
                age: [{required: true, message: '年龄为必填项', trigger: 'blur'}],
                phoneNumber: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                orderDate: [{required: true, message: '预约日期为必填项', trigger: 'blur'}],
                sex: [{required: true, message: '性别为必填项', trigger: 'blur'}]
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            handleSelectionChange(val) {
                this.checkIds = val;
            },
            //批量删除
            deList() {
                var ids = this.checkIds.map(item => item.id);
                this.$confirm("您确定要批量删除当前这些预约数据吗?", "提示", {type: "warning"}).then(() => {
                    axios.post("/orderSettinglist/deleteBatchesIds/" + ids + '.do').then((response) => {
                        if (response.data.flag) {
                            this.$message.success("已取消预约，取消预约信息已发送至您的手机，请查收!!!");
                        } else {
                            //删除失败
                            this.$message.error(response.data.message);
                        }
                    }).catch((response) => {
                        //显示权限是否满足,给出相应提示
                        this.showMessage(response);
                    }).finally(() => {
                        this.findPage();
                    });
                })
            },
            //确定预约
            handleUpdate(row) {
                this.$confirm("您确定预约吗?", "提示", {type: "warning"}).then(() => {
                    //给用户发送短信
                    axios.post("/orderSettinglist/send4OrderSettingList.do", row).then((response) => {
                        if (response.data.flag) {
                            //发送成功
                            this.$message.success("预约成功,预约信息已发送至您的手机,请查收!!!");

                            //短信发送成功,修改预约状态
                            axios.post("/orderSettinglist/updateOrderStatus.do?id=" + row.id).then((response) => {
                                if (response.data.flag) {
                                    this.formDate = response.data.data;
                                } else {
                                    //修改失败
                                    this.$message.error(response.data.message);
                                }
                            }).finally(() => {
                                //不管成功或者失败,都会执行
                                this.findPage();
                            });
                        } else {
                            //发送失败
                            this.$message.error(response.data.message);
                        }
                    }).catch((response) => {
                        //显示权限是否满足,给出相应提示
                        this.showMessage(response);
                    }).finally(() => {
                        //不管成功或者失败,都会执行
                        this.findPage();
                    });
                });
            },
            //添加预约信息
            handleAdd() {
                //调用已经编写好的校验身份证号的js代码. 校验用户输入的身份证号信息
                if (!checkIdCard(this.formData.idCard)) {
                    //校验不通过
                    this.$message.error("请输入正确的身份证号");
                    //return 之后就表示终止程序,下面的代码就不会再执行了
                    return false;
                }
                //调用已经编写好的校验手机号的js代码. 校验用户输入的手机号信息
                if (!checkTelephone(this.formData.phoneNumber)) {
                    //校验不通过
                    this.$message.error("请输入正确的手机号");
                    //return 之后就表示终止程序,下面的代码就不会再执行了
                    return false;
                }
                if(this.setmealIds==0){
                    this.$message.error("您尚未选择套餐，请选择您需要的套餐!!!");
                    return false;
                }
                //前端表单校验
                this.$refs["dataAddForm"].validate((valid) => {
                    if (valid) {
                        //隐藏添加弹框
                        this.dialogFormVisible = false;
                        this.activeName = 'first';

                        axios.post("/orderSettinglist/add/" + this.setmealIds + '.do', this.formData).then((response) => {
                            if (response.data.flag) {
                                //添加成功
                                this.$message.success(response.data.message);
                            } else {
                                //添加失败
                                this.$message.error(response.data.message);
                            }
                        }).catch((response) => {
                            //显示权限是否满足,给出相应提示
                            this.showMessage(response);
                        }).finally(() => {
                            this.findPage();
                            //重置表单数据  套餐ID数据
                            this.resetForm();
                        });
                    } else {
                        //前端表单数据校验不通过
                        return false;
                    }
                })
            },
            // 重置表单
            resetForm() {
                //重置新增弹窗中的内容
                this.formData = {};
                //重置套餐列表复选框内容
                this.setmealIds = [];
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增弹窗
                this.dialogFormVisible = true;
                //新增窗口中总是显示基本信息
                this.activeName = 'first';
                //重置新增弹窗中的内容
                this.resetForm();
                //当新增弹窗弹出后,发送异步请求,查询所有的检查项信息
                axios.get("/setmeal/findAll.do").then((response) => {
                    if (response.data.flag) {
                        //查询数据成功,将查询到的数据回显到页面
                        this.tableData = response.data.data;
                    } else {
                        //查询数据失败
                        this.$message.error(response.data.message);
                    }
                }).catch((response) => {
                    //显示权限是否满足,给出相应提示
                    this.showMessage(response);
                }).catch((response) => {
                    //显示权限是否满足,给出相应提示
                    this.showMessage(response);
                });
            },
            //分页查询
            findPage() {
                //定义分页模型数据
                params = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                //发送异步请求
                axios.post("/orderSettinglist/findByPage.do", params).then((response) => {
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },
            // 弹出编辑弹框
            handleDelete(row) {
                this.$confirm("您确定要删除当前这条预约数据吗?", "提示", {type: "warning"}).then(() => {
                    //删除单条预约列表信息
                    axios.post("/orderSettinglist/deleteList/" + row.id + '.do').then((response) => {
                        if (response.data.flag) {
                            this.$message.success("已取消预约，取消预约信息已发送至您的手机，请查收!!!");
                        } else {
                            this.$message.error("取消预约失败!");
                        }
                    }).catch((response) => {
                        //显示权限是否满足,给出相应提示
                        this.showMessage(response);
                    }).finally(() => {
                        this.findPage();
                    })
                })
            },
            //返回第一页
            back2Page1() {
                location.href = "ordersettinglist.html";
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //定义权限相关提示
            showMessage(response) {
                if (response == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('sorry，您没有相应权限，请与管理员联系!!!');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            }
        }
    })
</script>
</html>


